package net.wicp.tams.common.binlog.self.replication;

import java.io.IOException;

import net.wicp.tams.common.binlog.self.LogBuffer;
import net.wicp.tams.common.binlog.self.bean.Host;
import net.wicp.tams.common.binlog.self.bean.PacketBean;
import net.wicp.tams.common.thread.threadlocal.PerthreadManager;

public abstract class AbsPacketRead implements IPacketRead {
	private static final long serialVersionUID = 1L;
	protected final PacketBean packetBean;
	protected final LogBuffer buff;
	protected final String charsetName;

	public AbsPacketRead(PacketBean packetBean) {
		this.packetBean = packetBean;
		Host hostpre = (Host) PerthreadManager.getInstance().createValue("zorro-host",Host.class).get(new Host());
		this.charsetName = hostpre.getCharsetName();
		this.buff = packetBean.getBody();
		try {
			readBody();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected abstract void readBody() throws IOException;

	@Override
	public int getLength() {
		return this.packetBean.getLength();
	}

	@Override
	public int getSequence() {
		return packetBean.getSequence();
	}

}
